package arch.chameleon.module.web.bind;

import javax.servlet.ServletRequest;

import org.springframework.beans.MutablePropertyValues;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.web.multipart.MultipartRequest;
import org.springframework.web.util.WebUtils;

/**
 * Body data binder
 * @author George
 *
 */
public class ServletRequestBodyDataBinder extends ServletRequestDataBinder {

	public ServletRequestBodyDataBinder(Object target) {
		super(target);
	}
	
	public ServletRequestBodyDataBinder(Object target, String objectName) {
		super(target, objectName);
	}
	
	@Override
	public void bind(ServletRequest request) {
		//重构为从属性重获取参数
		MutablePropertyValues mpvs = new ServletRequestBodyPropertyValues(request);
		MultipartRequest multipartRequest = WebUtils.getNativeRequest(request, MultipartRequest.class);
		if (multipartRequest != null) {
			bindMultipart(multipartRequest.getMultiFileMap(), mpvs);
		}
		addBindValues(mpvs, request);
		doBind(mpvs);
	}
}
